<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 6.2.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.3/css/all.min.css" integrity="sha256-2H3fkXt6FEmrReK448mDVGKb3WW2ZZw35gI7vqHOE4Y=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"singingxy.github.io","root":"/","images":"/images","scheme":"Gemini","version":"8.6.1","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":false,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"}}</script><script src="/js/config.js"></script>
<meta name="description" content="总的说主要操作是在本地生成 ssh Key，然后把 ssh Key 添加到 Github&#x2F;GitLab 的账户上，完成连接。">
<meta property="og:type" content="article">
<meta property="og:title" content="使用ssh连接Git仓库(Github\GitLab\CODING\码云等)">
<meta property="og:url" content="https://singingxy.github.io/2019/sshKey-Git/index.html">
<meta property="og:site_name" content="sing&#39;s blog">
<meta property="og:description" content="总的说主要操作是在本地生成 ssh Key，然后把 ssh Key 添加到 Github&#x2F;GitLab 的账户上，完成连接。">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2019-12-23T00:22:16.000Z">
<meta property="article:modified_time" content="2019-12-23T00:22:16.000Z">
<meta property="article:author" content="Sing">
<meta property="article:tag" content="ssh">
<meta property="article:tag" content="Git">
<meta property="article:tag" content="Github">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="https://singingxy.github.io/2019/sshKey-Git/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://singingxy.github.io/2019/sshKey-Git/","path":"/2019/sshKey-Git/","title":"使用ssh连接Git仓库(Github\\GitLab\\CODING\\码云等)"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>使用ssh连接Git仓库(Github\GitLab\CODING\码云等) | sing's blog</title>
  




  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">sing's blog</h1>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">C'est La Vie Mon Ami.</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>







</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%A3%80%E6%9F%A5%E7%8E%B0%E6%9C%89-ssh-%E5%AF%86%E9%92%A5"><span class="nav-number">1.</span> <span class="nav-text">检查现有 ssh 密钥</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%94%9F%E6%88%90%E6%96%B0-ssh-%E5%AF%86%E9%92%A5"><span class="nav-number">2.</span> <span class="nav-text">生成新 ssh 密钥</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%BB%99%E8%B4%A6%E6%88%B7%E6%B7%BB%E5%8A%A0-ssh"><span class="nav-number">3.</span> <span class="nav-text">给账户添加 ssh</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%B5%8B%E8%AF%95-ssh-%E8%BF%9E%E6%8E%A5"><span class="nav-number">4.</span> <span class="nav-text">测试 ssh 连接</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%BD%BF%E7%94%A8-VS-Code-%E5%B0%9D%E8%AF%95%E5%90%8C%E6%AD%A5"><span class="nav-number">5.</span> <span class="nav-text">使用 VS Code 尝试同步</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%A6%82%E4%BD%95%E4%BF%AE%E6%94%B9%E6%9C%AC%E5%9C%B0%E6%8F%90%E4%BA%A4%E6%97%B6%E8%AE%B0%E5%BD%95%E7%9A%84%E5%AF%86%E7%A0%81"><span class="nav-number">6.</span> <span class="nav-text">如何修改本地提交时记录的密码</span></a></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-overview">
            <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">Sing</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives">
          <span class="site-state-item-count">18</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
        <span class="site-state-item-count">2</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
        <span class="site-state-item-count">25</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



          </div>
        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://singingxy.github.io/2019/sshKey-Git/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="Sing">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="sing's blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          使用ssh连接Git仓库(Github\GitLab\CODING\码云等)
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2019-12-23 08:22:16" itemprop="dateCreated datePublished" datetime="2019-12-23T08:22:16+08:00">2019-12-23</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E7%AC%94%E8%AE%B0/" itemprop="url" rel="index"><span itemprop="name">笔记</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <p>总的说主要操作是在本地生成 ssh Key，然后把 ssh Key 添加到 Github/GitLab 的账户上，完成连接。</p>
<span id="more"></span>

<h3 id="检查现有-ssh-密钥"><a href="#检查现有-ssh-密钥" class="headerlink" title="检查现有 ssh 密钥"></a>检查现有 ssh 密钥</h3><p>打开 Git Bash 终端。</p>
<p>输入 <code>ls -al ~/.ssh</code> 查看是否已经存在 ssh 密钥：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">\$ ls -al ~/.ssh</span><br></pre></td></tr></table></figure>

<p>如果提示不存在此目录那么就来生成新 ssh 密钥</p>
<p>如果已经存在 ssh 密匙文件应该是长下面这个样子：</p>
<blockquote>
<p>id_rsa.pub<br>id_ecdsa.pub<br>id_ed25519.pub<br>就可以跳过创建 SSH 密钥这一步啦。</p>
</blockquote>
<h3 id="生成新-ssh-密钥"><a href="#生成新-ssh-密钥" class="headerlink" title="生成新 ssh 密钥"></a>生成新 ssh 密钥</h3><p>打开 Git Bash 终端输入<code>ssh-keygen -t rsa -C &lt;your_email@example.com&gt;</code>( 你的邮箱)</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">ssh-keygen -t rsa -b 4096 -C &lt;your_email@example.com&gt;</span><br><span class="line"><span class="comment"># Creates a new ssh key, using the provided email as a label</span></span><br><span class="line"><span class="comment"># Generating public/private rsa key pair.</span></span><br><span class="line">Enter file <span class="keyword">in</span> <span class="built_in">which</span> to save the key (/Users/you/.ssh/id_rsa): [Press enter]  //enter使用默认地址， 如果需要使用多个Git仓库可以重命名</span><br><span class="line">Enter passphrase (empty <span class="keyword">for</span> no passphrase):   //这里点击 Enter 键即可，也可以填写密码，填写密码后每次使用 ssh 方式推送代码时都会要求输入密码</span><br></pre></td></tr></table></figure>

<p>成功之后显示如下信息：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">Your identification has been saved <span class="keyword">in</span> /Users/you/.ssh/id_rsa.</span><br><span class="line"><span class="comment"># Your public key has been saved in /Users/you/.ssh/id_rsa.pub.</span></span><br><span class="line"><span class="comment"># The key fingerprint is:</span></span><br><span class="line"><span class="comment"># 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@example.com</span></span><br></pre></td></tr></table></figure>

<h3 id="给账户添加-ssh"><a href="#给账户添加-ssh" class="headerlink" title="给账户添加 ssh"></a>给账户添加 ssh</h3><p>到路径<code>/Users/用户名/.ssh/</code>下，使用编辑器打开刚刚创建的<code>id_rsa.pub</code>文件，复制下整段内容。<br>打开 Github\GitLab\CODING\码云 的账户设置，找到设置 ssh 的选项，点击新增 ssh 密钥。由于各网站的设置位置都有不同，就不一一详说了。<br>把刚刚复制的 Key 粘贴进去，可以起一个方便你分辨的名字。<br>然后会提示你输入密码，输入完毕后 ssh Key 就添加成功了。</p>
<h3 id="测试-ssh-连接"><a href="#测试-ssh-连接" class="headerlink" title="测试 ssh 连接"></a>测试 ssh 连接</h3><p>在 Git Bash 里使用命令<code>ssh -T git@github.com</code>测试 ssh 连接，如果是 GitLab 则是<code>ssh -T git@gitlab.com</code>，其他账户同理。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">ssh -T git@github.com</span><br><span class="line">&gt; The authenticity of host <span class="string">&#x27;github.com (IP ADDRESS)&#x27;</span> can<span class="string">&#x27;t be established.</span></span><br><span class="line"><span class="string">&gt; RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.</span></span><br><span class="line"><span class="string">&gt; Are you sure you want to continue connecting (yes/no)? //输入 yes</span></span><br><span class="line"><span class="string">&gt; Hi username! You&#x27;</span>ve successfully authenticated, but GitHub does not</span><br><span class="line">&gt; provide shell access.</span><br></pre></td></tr></table></figure>

<p>收到欢迎消息说明连接成功。</p>
<h3 id="使用-VS-Code-尝试同步"><a href="#使用-VS-Code-尝试同步" class="headerlink" title="使用 VS Code 尝试同步"></a>使用 VS Code 尝试同步</h3><p>把要用的仓库 clone 到本地，放进 vscode 工作区，修改一些内容，可以看到改动的内容被识别出来了。<br>push 一下试试，输入用户名密码，成功。<br>如果密码输错了可以修改凭据</p>
<h3 id="如何修改本地提交时记录的密码"><a href="#如何修改本地提交时记录的密码" class="headerlink" title="如何修改本地提交时记录的密码"></a>如何修改本地提交时记录的密码</h3><p>控制面板-用户账户-管理 Windows 凭据-找到要修改的那一个，点编辑就可以修改密码了。</p>

    </div>

    
    
    

    <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/ssh/" rel="tag"># ssh</a>
              <a href="/tags/Git/" rel="tag"># Git</a>
              <a href="/tags/Github/" rel="tag"># Github</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2019/HTTP-request/" rel="prev" title="HTTP请求">
                  <i class="fa fa-chevron-left"></i> HTTP请求
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2019/Introduction-to-MVVM/" rel="next" title="理解MVVM">
                  理解MVVM <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Sing</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script>

  




  





</body>
</html>
